package com.sptpc.demo.controller;

import com.sptpc.demo.model.Drink;
import lombok.val;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import static com.fasterxml.jackson.databind.util.ClassUtil.name;

@Controller
public class RouterController {

    //首页（登录）路由
    @GetMapping("/")
    public String index(){
        return "manage/login";
    }

    //后台首页路由
    @GetMapping("manage/index")
    public String adminIndex(){
        return "manage/index";
    }

    //后台欢迎页面路由
    @GetMapping("/drink/addform")
    public String drinkAddFrom(){
        return "drink/add";
    }

    //饮品修改页路由
    //get /drink/updateform?id=13
    @GetMapping("/drink/update")
    public ModelAndView drinkUpdateFrom(@RequestParam Integer id){
         ModelAndView mv= new ModelAndView("drink/edit");
        //TOOD:从数据库通过id查询出对应饮品信息
        Drink build = Drink.builder().id(13)
                .name("茉莉花茶")
                .price(Money.of(CurrencyUnit.of("CNY"),12.00))
                .build();

        mv.addObject("data",build);
        return mv;
    }
}
